/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.ufrpe.bsi.pvs.view.assistant;

import br.ufrpe.bsi.pvs.view.PvsFrame;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JLabel;

/**
 *
 * @author sergio
 */
public class TelaPeso extends javax.swing.JPanel {

    public static TelaPeso INSTANCE = new TelaPeso();
    
    private TelaPeso() {
        initComponents();
        
        lb0.addMouseListener(new WeightHandler() );
        lb1.addMouseListener(new WeightHandler() );
        lb2.addMouseListener(new WeightHandler() );
        lb3.addMouseListener(new WeightHandler() );
        lb4.addMouseListener(new WeightHandler() );
        lb5.addMouseListener(new WeightHandler() );
        lb6.addMouseListener(new WeightHandler() );
        lb7.addMouseListener(new WeightHandler() );
        lb8.addMouseListener(new WeightHandler() );
        lb9.addMouseListener(new WeightHandler() );
        lbComma.addMouseListener(new WeightHandler() );
        lbClean.addMouseListener(new WeightHandler() );
        lbOk.addMouseListener(new WeightHandler() );        
    }
    
    

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        txtPeso = new javax.swing.JTextField();
        lbnull = new javax.swing.JLabel();
        lb9 = new javax.swing.JLabel();
        lb8 = new javax.swing.JLabel();
        lb7 = new javax.swing.JLabel();
        lbnull1 = new javax.swing.JLabel();
        lb6 = new javax.swing.JLabel();
        lb5 = new javax.swing.JLabel();
        lb4 = new javax.swing.JLabel();
        lbnull2 = new javax.swing.JLabel();
        lb3 = new javax.swing.JLabel();
        lb2 = new javax.swing.JLabel();
        lb1 = new javax.swing.JLabel();
        lbnull3 = new javax.swing.JLabel();
        lbComma = new javax.swing.JLabel();
        lb0 = new javax.swing.JLabel();
        lbClean = new javax.swing.JLabel();
        lbnull4 = new javax.swing.JLabel();
        lbOk = new javax.swing.JLabel();
        lbnull5 = new javax.swing.JLabel();

        setBackground(java.awt.Color.white);
        setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 20, 15));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/back.png"))); // NOI18N
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });
        add(jLabel1);

        jLabel15.setBackground(java.awt.Color.black);
        jLabel15.setFont(new java.awt.Font("Gabriola", 0, 36)); // NOI18N
        jLabel15.setForeground(java.awt.Color.white);
        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("Informe seu Peso");
        jLabel15.setToolTipText("");
        jLabel15.setMaximumSize(new java.awt.Dimension(1920, 45));
        jLabel15.setMinimumSize(new java.awt.Dimension(480, 45));
        jLabel15.setOpaque(true);
        jLabel15.setPreferredSize(new java.awt.Dimension(1115, 45));
        add(jLabel15);

        jLabel3.setBackground(java.awt.Color.white);
        jLabel3.setFont(new java.awt.Font("Georgia", 0, 36)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setToolTipText("");
        jLabel3.setMaximumSize(new java.awt.Dimension(1920, 10));
        jLabel3.setMinimumSize(new java.awt.Dimension(480, 10));
        jLabel3.setPreferredSize(new java.awt.Dimension(1115, 10));
        add(jLabel3);

        jPanel2.setOpaque(false);
        jPanel2.setPreferredSize(new java.awt.Dimension(330, 455));

        txtPeso.setFont(new java.awt.Font("Gabriola", 0, 18)); // NOI18N
        txtPeso.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtPeso.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)), javax.swing.BorderFactory.createEmptyBorder(5, 15, 5, 15)));
        txtPeso.setPreferredSize(new java.awt.Dimension(220, 40));
        jPanel2.add(txtPeso);

        lbnull.setBackground(java.awt.Color.white);
        lbnull.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lbnull.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbnull.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        lbnull.setMaximumSize(new java.awt.Dimension(70, 70));
        lbnull.setMinimumSize(new java.awt.Dimension(70, 70));
        lbnull.setOpaque(true);
        lbnull.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lbnull);

        lb9.setBackground(java.awt.Color.white);
        lb9.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lb9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb9.setText("9");
        lb9.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lb9.setMaximumSize(new java.awt.Dimension(70, 70));
        lb9.setMinimumSize(new java.awt.Dimension(70, 70));
        lb9.setOpaque(true);
        lb9.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lb9);

        lb8.setBackground(java.awt.Color.white);
        lb8.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lb8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb8.setText("8");
        lb8.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lb8.setMaximumSize(new java.awt.Dimension(70, 70));
        lb8.setMinimumSize(new java.awt.Dimension(70, 70));
        lb8.setOpaque(true);
        lb8.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lb8);

        lb7.setBackground(java.awt.Color.white);
        lb7.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lb7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb7.setText("7");
        lb7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lb7.setMaximumSize(new java.awt.Dimension(70, 70));
        lb7.setMinimumSize(new java.awt.Dimension(70, 70));
        lb7.setOpaque(true);
        lb7.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lb7);

        lbnull1.setBackground(java.awt.Color.white);
        lbnull1.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lbnull1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbnull1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        lbnull1.setMaximumSize(new java.awt.Dimension(70, 70));
        lbnull1.setMinimumSize(new java.awt.Dimension(70, 70));
        lbnull1.setOpaque(true);
        lbnull1.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lbnull1);

        lb6.setBackground(java.awt.Color.white);
        lb6.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lb6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb6.setText("6");
        lb6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lb6.setMaximumSize(new java.awt.Dimension(70, 70));
        lb6.setMinimumSize(new java.awt.Dimension(70, 70));
        lb6.setOpaque(true);
        lb6.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lb6);

        lb5.setBackground(java.awt.Color.white);
        lb5.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lb5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb5.setText("5");
        lb5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lb5.setMaximumSize(new java.awt.Dimension(70, 70));
        lb5.setMinimumSize(new java.awt.Dimension(70, 70));
        lb5.setOpaque(true);
        lb5.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lb5);

        lb4.setBackground(java.awt.Color.white);
        lb4.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lb4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb4.setText("4");
        lb4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lb4.setMaximumSize(new java.awt.Dimension(70, 70));
        lb4.setMinimumSize(new java.awt.Dimension(70, 70));
        lb4.setOpaque(true);
        lb4.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lb4);

        lbnull2.setBackground(java.awt.Color.white);
        lbnull2.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lbnull2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbnull2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        lbnull2.setMaximumSize(new java.awt.Dimension(70, 70));
        lbnull2.setMinimumSize(new java.awt.Dimension(70, 70));
        lbnull2.setOpaque(true);
        lbnull2.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lbnull2);

        lb3.setBackground(java.awt.Color.white);
        lb3.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lb3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb3.setText("3");
        lb3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lb3.setMaximumSize(new java.awt.Dimension(70, 70));
        lb3.setMinimumSize(new java.awt.Dimension(70, 70));
        lb3.setOpaque(true);
        lb3.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lb3);

        lb2.setBackground(java.awt.Color.white);
        lb2.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lb2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb2.setText("2");
        lb2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lb2.setMaximumSize(new java.awt.Dimension(70, 70));
        lb2.setMinimumSize(new java.awt.Dimension(70, 70));
        lb2.setOpaque(true);
        lb2.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lb2);

        lb1.setBackground(java.awt.Color.white);
        lb1.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lb1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb1.setText("1");
        lb1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lb1.setMaximumSize(new java.awt.Dimension(70, 70));
        lb1.setMinimumSize(new java.awt.Dimension(70, 70));
        lb1.setOpaque(true);
        lb1.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lb1);

        lbnull3.setBackground(java.awt.Color.white);
        lbnull3.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lbnull3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbnull3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        lbnull3.setMaximumSize(new java.awt.Dimension(70, 70));
        lbnull3.setMinimumSize(new java.awt.Dimension(70, 70));
        lbnull3.setOpaque(true);
        lbnull3.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lbnull3);

        lbComma.setBackground(java.awt.Color.white);
        lbComma.setFont(new java.awt.Font("SansSerif", 0, 24)); // NOI18N
        lbComma.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbComma.setText(",");
        lbComma.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lbComma.setMaximumSize(new java.awt.Dimension(70, 70));
        lbComma.setMinimumSize(new java.awt.Dimension(70, 70));
        lbComma.setOpaque(true);
        lbComma.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lbComma);

        lb0.setBackground(java.awt.Color.white);
        lb0.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lb0.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lb0.setText("0");
        lb0.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lb0.setMaximumSize(new java.awt.Dimension(70, 70));
        lb0.setMinimumSize(new java.awt.Dimension(70, 70));
        lb0.setOpaque(true);
        lb0.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lb0);

        lbClean.setBackground(java.awt.Color.white);
        lbClean.setFont(new java.awt.Font("Gabriola", 0, 18)); // NOI18N
        lbClean.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbClean.setText("Limpar");
        lbClean.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lbClean.setMaximumSize(new java.awt.Dimension(70, 70));
        lbClean.setMinimumSize(new java.awt.Dimension(70, 70));
        lbClean.setOpaque(true);
        lbClean.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lbClean);

        lbnull4.setBackground(java.awt.Color.white);
        lbnull4.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lbnull4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbnull4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        lbnull4.setMaximumSize(new java.awt.Dimension(70, 70));
        lbnull4.setMinimumSize(new java.awt.Dimension(70, 70));
        lbnull4.setOpaque(true);
        lbnull4.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lbnull4);

        lbOk.setBackground(java.awt.Color.white);
        lbOk.setFont(new java.awt.Font("Gabriola", 0, 18)); // NOI18N
        lbOk.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbOk.setText("OK");
        lbOk.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        lbOk.setMaximumSize(new java.awt.Dimension(70, 70));
        lbOk.setMinimumSize(new java.awt.Dimension(70, 70));
        lbOk.setOpaque(true);
        lbOk.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lbOk);

        lbnull5.setBackground(java.awt.Color.white);
        lbnull5.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        lbnull5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbnull5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        lbnull5.setMaximumSize(new java.awt.Dimension(70, 70));
        lbnull5.setMinimumSize(new java.awt.Dimension(70, 70));
        lbnull5.setOpaque(true);
        lbnull5.setPreferredSize(new java.awt.Dimension(70, 70));
        jPanel2.add(lbnull5);

        add(jPanel2);
    }// </editor-fold>//GEN-END:initComponents

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
        PvsFrame.INSTANCE.home();
    }//GEN-LAST:event_jLabel1MouseClicked

    private class WeightHandler extends MouseAdapter {
        
        @Override
        public void mouseEntered(MouseEvent e) {
            JLabel lb = (JLabel) e.getSource();
            lb.setBackground(new Color(227, 246, 255));
            lb.setBorder(BorderFactory.createLineBorder(new Color(151, 222, 255) ));
        }
        
        @Override
        public void mouseExited(MouseEvent e) {
            JLabel lb = (JLabel) e.getSource();
            lb.setBackground(Color.WHITE);
            lb.setBorder(BorderFactory.createLineBorder(new Color(204, 204, 204) ));
        }
        
        @Override
        public void mouseClicked(MouseEvent e) {
            JLabel lb = (JLabel) e.getSource();
            String txt = lb.getText();
            if (txt.equals(lbClean.getText()))
                txtPeso.setText("");
            else if (txt.equals(lbOk.getText())) {
            	double peso = Double.parseDouble(txtPeso.getText().replace(" kg", ""));
                Query.getInstance().setPeso(peso);
            	txtPeso.setText("");
                PvsFrame.INSTANCE.home();
            } else {
                String stringPeso = txtPeso.getText().replace(" kg", "");
                txtPeso.setText(stringPeso + txt + " kg");
            }
            
            mouseExited(e);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lb0;
    private javax.swing.JLabel lb1;
    private javax.swing.JLabel lb2;
    private javax.swing.JLabel lb3;
    private javax.swing.JLabel lb4;
    private javax.swing.JLabel lb5;
    private javax.swing.JLabel lb6;
    private javax.swing.JLabel lb7;
    private javax.swing.JLabel lb8;
    private javax.swing.JLabel lb9;
    private javax.swing.JLabel lbClean;
    private javax.swing.JLabel lbComma;
    private javax.swing.JLabel lbOk;
    private javax.swing.JLabel lbnull;
    private javax.swing.JLabel lbnull1;
    private javax.swing.JLabel lbnull2;
    private javax.swing.JLabel lbnull3;
    private javax.swing.JLabel lbnull4;
    private javax.swing.JLabel lbnull5;
    private javax.swing.JTextField txtPeso;
    // End of variables declaration//GEN-END:variables
}
